<template>
  <div>
    <el-table :data="feedbackList" border style="width: 100%">
      <el-table-column type="index" label="ID" width="50"></el-table-column>
      <el-table-column prop="title" label="问题反馈"></el-table-column>
      <el-table-column prop="created_at" label="时间" width="160"></el-table-column>
      <el-table-column label="操作" width="80">
        <template slot-scope="scope">
          <el-button @click="info(scope.row)" size="mini">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="margin-top-20 text-center" v-if="feedbackList.length">
      <el-pagination
        @size-change="pageSizeChange"
        @current-change="currentPageChange"
        :background="true"
        :current-page="page.currentPage"
        :page-sizes="[10, 20, 30]"
        :page-size="page.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      feedbackList: [],
      page: {
        total: 0,
        currentPage: 1,
        size: 10
      }
    }
  },
  mounted() {
    this.getFeedbackListData();
  },
  methods: {
    getFeedbackListData() {
      let id = this.$store.state.doctorInfo.id;

      this.axios.get('/doctor/'+id+'/feedbacks/list', {
        params: {
          pageSize: this.page.size,
          currentPage: this.page.currentPage
        }
      }).then((response) => {
        if(response.data.code == 200){
          this.feedbackList = response.data.data.data;
          this.page.total = response.data.data.total;
        }else{
          this.$message({
            message: '数据加载失败!',
            type: 'error'
          });
        }
      });
    },
    pageSizeChange(val) {
      this.page.currentPage = 1;
      this.page.size = val;
      this.getFeedbackListData();
    },
    currentPageChange(val) {
      this.page.currentPage = val;
      this.getFeedbackListData();
    },
    info(row) {
      this.$router.push({name: 'FeedbackInfo', params: {id: row.id}});
    }
  }
}
</script>
